package com.wgts.wgts.mvp.view.activity.tasklobby;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wgts.wgts.R;
import com.wgts.wgts.netmodle.resp.TaskDetailEntity;
import com.wgts.wgts.tools.CustomImageView;
import com.wgts.wgts.tools.MoHuGlide;
import com.wgts.wgts.tools.Tools;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 */
public class TaskImageAdapter extends RecyclerView.Adapter<TaskImageAdapter.ViewHold> {
    private Context context;
    private List<TaskDetailEntity.Url> list;
    private List<View> views;

    public List<ViewHold> myViewHolderList = new ArrayList<>();

    public TaskImageAdapter(Context context, List<TaskDetailEntity.Url> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.wgts_task_image_adapter_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, int i) {
        MoHuGlide.getInstance().glideImgsFormList(viewHold.taskImage, list.get(i).filePath, context);

        //holder绑定对应的position
        viewHold.setDataPosition(i);
        //判断list是否还有该holder， 没有就增加
        //因为list已经持有holder的引用，所有数据自动会改变
        if (!myViewHolderList.contains(viewHold)){
            myViewHolderList.add(viewHold);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.task_image)
        ImageView taskImage;
        private int position;
        private void setDataPosition(int position){
            this.position = position;
        }

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public List<View> getImageView(){
        views = new ArrayList<>();
        for (int i = 0; i < myViewHolderList.size(); i++){
            views.add(myViewHolderList.get(i).taskImage);
        }
        return views;
    }

}
